<template>
  <div class="authors-list">
    <NavBar />
    <div class="authors-grid content-wrapper">
      <div v-for="author in authors" :key="author.id" class="author-card" @click="goToAuthorDetail(author.id)">
        <img :src="author.picture" alt="作者头像" class="author-image">
        <h3 class="author-name">{{ author.name }}</h3>
      </div>
    </div>
    <Footer />
  </div>
</template>

<script>
import NavBar from '@/components/NavBar.vue'
import Footer from '@/components/Footer.vue'

export default {
  components: {
    NavBar,
    Footer
  },
  data() {
    return {
      authors: []
    }
  },
  mounted() {
    this.$http.get('/authors')
      .then((response) => {
        // console.log("所有作者",response.data);
        this.authors = response.data;
      })
      .catch((error) => {
        console.error('获取作者列表失败:', error);
      });
  },
  methods: {
    goToAuthorDetail(authorId) {
      this.$router.push({ name: 'AuthorDetail', params: { authorId } });
    }
  }
}
</script>

<style scoped>
.authors-list {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.authors-grid {
  flex: 0 0 80%; 
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  padding: 20px;
}

.author-card {
  background: #f9fafb;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.author-card:hover {
  transform: scale(1.05);
}

.author-image {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 10px;
}

.author-name {
  font-size: 18px;
  color: #333;
}
</style>